﻿package frEngine.shader.filters.fragmentFilters
{
    import __AS3__.vec.*;
    import baseEngine.core.*;
    import baseEngine.system.*;
    import frEngine.shader.*;
    import frEngine.shader.filters.*;

    public class EnvMapFilter extends FilterBase
    {
        private var fcEnvmapAlpha:Vector.<Number>;
        private var fcCommon:Vector.<Number>;
        private var cube:Texture3D;

        public function EnvMapFilter(param1:Texture3D)
        {
            this.fcEnvmapAlpha = this.Vector.<Number>([1, 0, 0, 0]);
            this.fcCommon = this.Vector.<Number>([0.5, 0, 1 / 255, 1]);
            super(FilterType.EnvMapFilter, FilterPriority.EnvMapFilter);
            this.cube = param1;
            return;
        }// end function

        override public function setRegisterParams(param1:Program3dRegisterInstance) : void
        {
            return;
        }// end function

        override public function get programeId() : String
        {
            return "EnvMapFilter0";
        }// end function

        override public function clone() : FilterBase
        {
            return this;
        }// end function

        override public function createVertexCode(param1:Program3dRegisterInstance, param2:int) : String
        {
            var _loc_3:* = new Array();
            _loc_3.push(new ToBuilderInfo("vf1", "{V_GloblePos}", false, 1));
            param1.toBuild("", _loc_3);
            return "";
        }// end function

        override public function createFragmentColor(param1:Program3dRegisterInstance, param2:Boolean) : String
        {
            var _loc_3:* = new Array();
            _loc_3.push(new ToBuilderInfo("fs3", "{envMap}", false, 1, this.cube));
            _loc_3.push(new ToBuilderInfo("fc0", "{fcCommon}", false, 1, this.fcCommon));
            _loc_3.push(new ToBuilderInfo("fc8", "{fcEnvmapAlpha}", false, 1, this.fcEnvmapAlpha));
            _loc_3.push(new ToBuilderInfo("fc12", "{CamPos}", false, 1, Global3D.scene.cpos));
            var _loc_4:* = "sub ft1, {CamPos}, {V_GloblePos} \n" + "nrm ft1.xyz, ft1 \n" + "mov ft1.w,   {fcCommon}.y \n" + "";
            _loc_4 = param1.toBuild(_loc_4, _loc_3);
            return _loc_4;
        }// end function

        public static function compileEnvMapFragmentCode(param1:String, param2:String, param3:String, param4:String, param5:String, param6:String, param7:String, param8:String) : String
        {
            var _loc_9:* = "dp3 " + param6 + ".w, " + param2 + ".xyz, " + param1 + ".xyz \n" + "add " + param6 + ".w, " + param6 + ".w, " + param6 + ".w \n" + "mul " + param6 + ".xyz, " + param1 + ".xyz, " + param6 + ".w \n" + "sub " + param6 + ".xyz, " + param6 + ".xyz, " + param2 + ".xyz \n" + "tex " + param6 + ", " + param6 + ", " + param5 + " <cube,clamp,linear> \n" + "sub " + param7 + ".w, " + param6 + ".w, " + param3 + ".x \n" + "kil " + param7 + ".w \n" + "sub " + param6 + ", " + param6 + ", " + param8 + " \n" + "mul " + param6 + ", " + param6 + ", " + param4 + ".x \n" + "add " + param8 + ", " + param8 + ", " + param6 + " \n" + "";
            return _loc_9;
        }// end function

        public static function anzSkyBoxFileName(param1:String) : Vector.<String>
        {
            var _loc_4:int = 0;
            param1 = param1.toLocaleLowerCase();
            var _loc_2:String = "";
            var _loc_3:String = "";
            _loc_4 = param1.indexOf(".");
            _loc_2 = param1.substr((_loc_4 - 1), 1);
            _loc_4 = param1.indexOf("neg");
            if (_loc_4 > -1)
            {
                _loc_3 = param1.substr(_loc_4, 3);
            }
            _loc_4 = param1.indexOf("pos");
            if (_loc_4 > -1)
            {
                _loc_3 = param1.substr(_loc_4, 3);
            }
            return EnvMapFilter.Vector.<String>([_loc_3, _loc_2]);
        }// end function

    }
}
